package net.maku.propagate.controller;

import cn.hutool.core.bean.BeanUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.propagate.convert.PropagateInnovationStudioConvert;
import net.maku.propagate.entity.PropagateInnovationStudioEntity;
import net.maku.propagate.service.PropagateInnovationStudioService;
import net.maku.propagate.query.PropagateInnovationStudioQuery;
import net.maku.propagate.vo.PropagateInnovationStudioVO;
import net.maku.system.service.SysDictDataService;
import net.maku.system.vo.SysDictDataVO;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* 创新工作室
*
* @author 阿沐 babamu@126.com
* @since 1.0.0 2025-03-16
*/
@RestController
@RequestMapping("propagate/innovation")
@Tag(name="创新工作室")
@AllArgsConstructor
public class PropagateInnovationStudioController {
    private final PropagateInnovationStudioService propagateInnovationStudioService;

    private final SysDictDataService sysDictDataService;

    @GetMapping("page")
    @Operation(summary = "分页")
    public Result<PageResult<PropagateInnovationStudioVO>> page(@ParameterObject @Valid PropagateInnovationStudioQuery query){
        Integer studioType = query.getStudioType();
        if(studioType != null && studioType < 0){
            query.setStudioType(null);
        }
        Integer listingLevel = query.getListingLevel();
        if(listingLevel != null && listingLevel < 0){
            query.setListingLevel(null);
        }
        PageResult<PropagateInnovationStudioVO> page = propagateInnovationStudioService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    public Result<PropagateInnovationStudioVO> get(@PathVariable("id") Long id){
        PropagateInnovationStudioVO detail = propagateInnovationStudioService.getDetail(id);
        return Result.ok(detail);
    }

    @GetMapping("getDictData")
    @Operation(summary = "获取字典数据")
    public Result getDictData(){
        List<SysDictDataVO> studioType = sysDictDataService.selectDictDataByType("studio_type");
        List<SysDictDataVO> studioListingLevel = sysDictDataService.selectDictDataByType("studio_listing_level");
        Map<String,Object> map = new HashMap<>();
        map.put("studioType",studioType);
        map.put("studioListingLevel",studioListingLevel);
        return Result.ok(map);
    }

}